
<h1><span class="yiyi-st" id="yiyi-12">numpy.busday_offset</span></h1>
        <blockquote>
        <p>原文：<a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.busday_offset.html">https://docs.scipy.org/doc/numpy/reference/generated/numpy.busday_offset.html</a></p>
        <p>译者：<a href="https://github.com/wizardforcel">飞龙</a> <a href="http://usyiyi.cn/">UsyiyiCN</a></p>
        <p>校对：（虚位以待）</p>
        </blockquote>
    
<dl class="function">
<dt id="numpy.busday_offset"><span class="yiyi-st" id="yiyi-13"> <code class="descclassname">numpy.</code><code class="descname">busday_offset</code><span class="sig-paren">(</span><em>dates</em>, <em>offsets</em>, <em>roll=&apos;raise&apos;</em>, <em>weekmask=&apos;1111100&apos;</em>, <em>holidays=None</em>, <em>busdaycal=None</em>, <em>out=None</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-14">首先根据<code class="docutils literal"><span class="pre">roll</span></code>规则将日期调整为有效日期，然后将偏移量应用于在有效天计算的给定日期。</span></p>
<div class="versionadded">
<p><span class="yiyi-st" id="yiyi-15"><span class="versionmodified">版本1.7.0中的新功能。</span></span></p>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name">
<col class="field-body">
<tbody valign="top">
<tr class="field-odd field"><th class="field-name"><span class="yiyi-st" id="yiyi-16">参数：</span></th><td class="field-body"><p class="first"><span class="yiyi-st" id="yiyi-17"><strong>日期</strong>：array_like of datetime64 [D]</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-18">要处理的日期的数组。</span></p>
</div></blockquote>
<p><span class="yiyi-st" id="yiyi-19"><strong>offsets</strong>：array_like of int</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-20">偏移数组，使用<code class="docutils literal"><span class="pre">dates</span></code>广播。</span></p>
</div></blockquote>
<p><span class="yiyi-st" id="yiyi-21"><strong>roll</strong>：{&apos;raise&apos;，&apos;nat&apos;，&apos;forward&apos;，&apos;following&apos;，&apos;backward&apos;，&apos;preceding&apos;，&apos;modifiedfollowing&apos;，&apos;modifiedpreceding&apos;</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-22">如何处理不在有效日期的日期。</span><span class="yiyi-st" id="yiyi-23">默认值为&apos;raise&apos;。</span></p>
<blockquote>
<div><ul class="simple">
<li><span class="yiyi-st" id="yiyi-24">“raise”是指为无效日提出异常。</span></li>
<li><span class="yiyi-st" id="yiyi-25">&apos;nat&apos;意味着返回一个无效日的NaT（不是一次）。</span></li>
<li><span class="yiyi-st" id="yiyi-26">“向前”和“跟随”意味着采取第一个有效的一天后的时间。</span></li>
<li><span class="yiyi-st" id="yiyi-27">“向后”和“在先”意味着采用时间上早的第一个有效日。</span></li>
<li><span class="yiyi-st" id="yiyi-28">&apos;modifiedfollowing&apos;意味着在第一个有效的日期之后，除非跨越一个月的边界，在这种情况下采取第一个有效的一天的时间。</span></li>
<li><span class="yiyi-st" id="yiyi-29">“modifiedpreceding”意味着取得第一个有效的时间，除非它跨越一个月的边界，在这种情况下采取第一个有效的一天后的时间。</span></li>
</ul>
</div></blockquote>
</div></blockquote>
<p><span class="yiyi-st" id="yiyi-30"><strong>weekmask</strong>：str或array_like of bool，可选</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-31">一个七元素数组，表示星期一到星期日是有效日期。</span><span class="yiyi-st" id="yiyi-32">可以指定为长度为七的列表或数组，如[1,1,1,1,1,0,0]；一个长度为七的字符串，如&apos;1111100&apos;；或像“星期二星期三星期三星期五”的字符串，由工作日的3个字符的缩写组成，可选地由空格分隔。</span><span class="yiyi-st" id="yiyi-33">有效的缩写是：周一周二周三周四周五周六周日</span></p>
</div></blockquote>
<p><span class="yiyi-st" id="yiyi-34"><strong>节假日</strong>：array_like of datetime64 [D]，可选</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-35">要视为无效日期的日期数组。</span><span class="yiyi-st" id="yiyi-36">它们可以以任何顺序指定，并且NaT（非一次性）日期被忽略。</span><span class="yiyi-st" id="yiyi-37">此列表以适用于快速计算有效天数的规范化形式保存。</span></p>
</div></blockquote>
<p><span class="yiyi-st" id="yiyi-38"><strong>busdaycal</strong>：busdaycalendar，可选</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-39">指定有效天数的<a class="reference internal" href="numpy.busdaycalendar.html#numpy.busdaycalendar" title="numpy.busdaycalendar"><code class="xref py py-obj docutils literal"><span class="pre">busdaycalendar</span></code></a>对象。</span><span class="yiyi-st" id="yiyi-40">如果提供此参数，则不能提供周期掩码和假日。</span></p>
</div></blockquote>
<p><span class="yiyi-st" id="yiyi-41"><strong>out</strong>：datetime64的数组[D]，可选</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-42">如果提供，此数组将填充结果。</span></p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name"><span class="yiyi-st" id="yiyi-43">返回：</span></th><td class="field-body"><p class="first"><span class="yiyi-st" id="yiyi-44"><strong>out</strong>：datetime64的数组[D]</span></p>
<blockquote class="last">
<div><p><span class="yiyi-st" id="yiyi-45">具有广播<code class="docutils literal"><span class="pre">dates</span></code>和<code class="docutils literal"><span class="pre">offsets</span></code>的形状的数组，包含应用偏移的日期。</span></p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title"><span class="yiyi-st" id="yiyi-46">也可以看看</span></p>
<dl class="last docutils">
<dt><span class="yiyi-st" id="yiyi-47"><a class="reference internal" href="numpy.busdaycalendar.html#numpy.busdaycalendar" title="numpy.busdaycalendar"><code class="xref py py-obj docutils literal"><span class="pre">busdaycalendar</span></code></a></span></dt>
<dd><span class="yiyi-st" id="yiyi-48">指定一组自定义有效天数的对象。</span></dd>
<dt><span class="yiyi-st" id="yiyi-49"><a class="reference internal" href="numpy.is_busday.html#numpy.is_busday" title="numpy.is_busday"><code class="xref py py-obj docutils literal"><span class="pre">is_busday</span></code></a></span></dt>
<dd><span class="yiyi-st" id="yiyi-50">返回指示有效天数的布尔数组。</span></dd>
<dt><span class="yiyi-st" id="yiyi-51"><a class="reference internal" href="numpy.busday_count.html#numpy.busday_count" title="numpy.busday_count"><code class="xref py py-obj docutils literal"><span class="pre">busday_count</span></code></a></span></dt>
<dd><span class="yiyi-st" id="yiyi-52">计算半天开放日期范围内有多少有效天数。</span></dd>
</dl>
</div>
<p class="rubric"><span class="yiyi-st" id="yiyi-53">例子</span></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="c1"># First business day in October 2011 (not accounting for holidays)</span>
<span class="gp">... </span><span class="n">np</span><span class="o">.</span><span class="n">busday_offset</span><span class="p">(</span><span class="s1">&apos;2011-10&apos;</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">roll</span><span class="o">=</span><span class="s1">&apos;forward&apos;</span><span class="p">)</span>
<span class="go">numpy.datetime64(&apos;2011-10-03&apos;,&apos;D&apos;)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Last business day in February 2012 (not accounting for holidays)</span>
<span class="gp">... </span><span class="n">np</span><span class="o">.</span><span class="n">busday_offset</span><span class="p">(</span><span class="s1">&apos;2012-03&apos;</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="n">roll</span><span class="o">=</span><span class="s1">&apos;forward&apos;</span><span class="p">)</span>
<span class="go">numpy.datetime64(&apos;2012-02-29&apos;,&apos;D&apos;)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Third Wednesday in January 2011</span>
<span class="gp">... </span><span class="n">np</span><span class="o">.</span><span class="n">busday_offset</span><span class="p">(</span><span class="s1">&apos;2011-01&apos;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="n">roll</span><span class="o">=</span><span class="s1">&apos;forward&apos;</span><span class="p">,</span> <span class="n">weekmask</span><span class="o">=</span><span class="s1">&apos;Wed&apos;</span><span class="p">)</span>
<span class="go">numpy.datetime64(&apos;2011-01-19&apos;,&apos;D&apos;)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># 2012 Mother&apos;s Day in Canada and the U.S.</span>
<span class="gp">... </span><span class="n">np</span><span class="o">.</span><span class="n">busday_offset</span><span class="p">(</span><span class="s1">&apos;2012-05&apos;</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">roll</span><span class="o">=</span><span class="s1">&apos;forward&apos;</span><span class="p">,</span> <span class="n">weekmask</span><span class="o">=</span><span class="s1">&apos;Sun&apos;</span><span class="p">)</span>
<span class="go">numpy.datetime64(&apos;2012-05-13&apos;,&apos;D&apos;)</span>
</pre></div>
</div>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="c1"># First business day on or after a date</span>
<span class="gp">... </span><span class="n">np</span><span class="o">.</span><span class="n">busday_offset</span><span class="p">(</span><span class="s1">&apos;2011-03-20&apos;</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">roll</span><span class="o">=</span><span class="s1">&apos;forward&apos;</span><span class="p">)</span>
<span class="go">numpy.datetime64(&apos;2011-03-21&apos;,&apos;D&apos;)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">busday_offset</span><span class="p">(</span><span class="s1">&apos;2011-03-22&apos;</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">roll</span><span class="o">=</span><span class="s1">&apos;forward&apos;</span><span class="p">)</span>
<span class="go">numpy.datetime64(&apos;2011-03-22&apos;,&apos;D&apos;)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># First business day after a date</span>
<span class="gp">... </span><span class="n">np</span><span class="o">.</span><span class="n">busday_offset</span><span class="p">(</span><span class="s1">&apos;2011-03-20&apos;</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">roll</span><span class="o">=</span><span class="s1">&apos;backward&apos;</span><span class="p">)</span>
<span class="go">numpy.datetime64(&apos;2011-03-21&apos;,&apos;D&apos;)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">busday_offset</span><span class="p">(</span><span class="s1">&apos;2011-03-22&apos;</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">roll</span><span class="o">=</span><span class="s1">&apos;backward&apos;</span><span class="p">)</span>
<span class="go">numpy.datetime64(&apos;2011-03-23&apos;,&apos;D&apos;)</span>
</pre></div>
</div>
</dd></dl>
